<template lang="jade">
div
	h-loader-full(url='loader')
	m-title(icon='add',name='职位管理>职位详情')
	table.single
		mf-row(name='公司名称：') {{p.cname}}
		mf-row(name='岗位类型：') 
			select(v-model='o.id',@change='onbig(o.id)')
				option(value='') 请选择
				option(v-for='o in big',:value='o.id') {{o.name}} 
			
			select(v-model='t.id',@change='onsmall(t.id)')
				option(value='') 请选择
				option(v-for='t in middle',:value='t.id') {{t.name}}

			select(v-model='p.jtid',id='cat')
				option(value='') 请选择
				option(v-for='n in small',:value='n.id') {{n.name}}

		mf-row(name='薪资水平：') 
			select(v-model='p.pay')
				option(value='') 请选择
				option(v-for='v in pay',:value='v') {{v}}
		mf-row(name='工作区域：')
			select(v-model='p.area')
				option(value='') 请选择
				option(v-for='v in area',:value='v.name') {{v.name}}
		mf-row(name='福利待遇：') 
			p
				span.be(v-for ='(v,i) in benefit',@click="join(v)",:class="{'bg': v.checked==true}") {{v.name}}
		mf-row(name='学历要求：',msg='必填')
			select(v-model='p.education')
				option(value='') 请选择
				option(v-for='v in education',:value='v') {{v}}
		mf-row(name='经验要求：',msg='必填')
			select(v-model='p.experience')
				option(value='') 请选择
				option(v-for='v in experience',:value='v') {{v}}
		mf-row(name='工作地址：',msg='必填')
			input(type='text',v-model='p.address',placeholder='请填写工作地址')
		mf-row(name='岗位职责：',msg='必填')
			textarea(v-model='p.statement',rows="5",placeholder='请填写岗位职责')
		mf-row(name='')
			button(@click='button') 确认提交
</template>
<script>
export default {
	data () {
		return {
			loader: {
				company:'get_company/datail/'+this.$query.get('id'),
				experience:'experience/list',
				pay:'pay/list',
				benefit:'benefit/list',
				education:'education/list',
				jobtype:'jobtype/list',
				area:'area/list'
			},
			p: {
				name:'',
				cname:'',
				jtid:'',
				pay: '',
				area: '',
				type:'',
				benefit: '',
				education: '',
				experience:'',
				address:'',
				statement:'',
				requirements: '',
			},
			o:{
				id:''
			},
			t:{
				id:''
			},
			com_type:[{id:1,name:'央企'},{id:2,name:'国企'},{id:0,name:'其他'}],
			type:['待审核','审核成功','审核失败'],
			company:[],
			experience:[],
			pay:[],
			benefit:[],
			education:[],
			jobtype:[],
			small:[],
			area:[],
			big:[],
			middle:[],
			small:[],
			bigid:null,
			beneAry:[],
		}
	},
	methods: {
		loadAfter(data){
			this.company = data.company
			this.p.cname = this.company[0][0].cname
			this.p.cid = this.$query.get('id')
			this.area = data.area
			this.experience = data.experience
			this.pay=data.pay
			this.benefit=data.benefit
			this.education = data.education
			this.jobtype = data.jobtype
			for(let v of this.jobtype){
        if(v.bid == 0){
          this.big.push(v)
        }
      }
			this.area = data.area
		},
		join(bene){
        bene.checked = !bene.checked
        if(bene.checked){
          this.beneAry.push(bene.name)
        }else{
          for(let i=0;i<this.beneAry.length;i++){
            if(this.beneAry[i] == bene.name){
              this.beneAry.splice(i,1)
              break
            }
          }
        }
        this.p.benefit = this.beneAry.join('|')
      },
		check(i,type){
      if(type){
        this.benefit[i].checked=false
				this.p.benefit.push() 
      }else{
        this.benefit[i].checked=true
      }
    },
		updateBefore(){
			let a=''
      let b= ''
      for(let v of this.benefit){
        if(v.checked==true){
          a += v.name +'|'
          b = a.substring(0,a.length-1)
        }
      }
      this.data.benefit = b
			return true
		},
		//联动
     onbig(id){
      this.middle=[]
      this.bigid = id
      for(let v of this.jobtype){
        if(v.bid==id&& v.mid ==0 ){
          this.middle.push(v)
        }
      }
    },
    onsmall(id){
      this.mid=id
      this.small=[]
     for(let v of this.jobtype){
        if(v.mid ==id ){
          this.small.push(v)
        }
      }
    },
		button(){
			if(this.p.jtid == ''){
				this.$msg.success('请选择岗位类型!')
				return
			}
			if(this.p.pay == ''){
				this.$msg.success('请选择薪资水平!')
				return
			}
			if(this.p.area == ''){
				this.$msg.success('请选择工作区域!')
				return
			}
			if(this.p.benefit == ''){
				this.$msg.success('请选择福利待遇!')
				return
			}
			if(this.p.education == ''){
				this.$msg.success('请选择学历要求!')
				return
			}

			if(this.p.experience == ''){
				this.$msg.success('请选择经验要求!')
				return
			}
			if(this.p.address == ''){
				this.$msg.success('请填写工作地址!')
				return
			}
			if(this.p.statement == ''){
				this.$msg.success('请填写岗位职责!')
				return
			}
			this.$ajax.post('job/add',this.p,(res)=>{
				this.$msg.success('添加成功')
				setTimeout("window.location.href='../examine/company_list.html'",1500)
			},(res)=>{
				this.$msg.error(res.message)
			})
		}
	},
}

</script>
<style lang="less" scoped>
@import "../../../plugin/style/mixin";
.be {
	 .mlr(5);.bsol(#f0f0f0);
}
.bg{
	.bk(#ee5)
}
.top{
	.c(red);
}

</style>